
const app = getApp()

Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		index:0,
		type:'',
		title:'',
		content:'',
		siteId: 340100,
		id: 0,
		isSubmit: true,
		reports: [
			'欺诈（虚假活动等）'
		],
		reportData: [
			'欺诈（虚假活动等）',
			'不实信息',
			'色情低俗',
			'未经授权/滥用原创',
			'其它',
		]
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		wx.showShareMenu({
			withShareTicket: false
		})

		this.setData({
			id: options.id,
			title: options.title,
			type: options.type,
		})

		console.log(options)
		let cityCode = wx.getStorageSync('cityCode')
		if (cityCode != undefined && cityCode != '') {
			this.setData({
				siteId: cityCode
			})
		}
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	handleCheckbox(e) {
		this.setData({
			reports: e.detail.value
		})
	},

	handleInput(e) {
		const name = e.target.dataset.name
		let val = []
		val[name] = e.detail.value
		this.setData(val)
	},

	textareaAInput(e) {
		this.setData({
			content: e.detail.value
		})
	},

	handleSubmit() {
		let vm = this;
		let title = decodeURIComponent(vm.data.title);
		let content = vm.data.content;
		let id = vm.data.id
		let type = vm.data.type

		if (this.data.reports.length == 0) {
			wx.showToast({
				title: '请选择反馈类型',
				icon: 'none',
				duration: 2000
			});
			return false;
		} else {

			let open_id = wx.getStorageSync('user_new')

			let data = {}
			data['type'] = type
			data['site_id'] = vm.data.siteId
			data['open_id'] = open_id
			data['title'] = title
			data['id'] = id
			data['content'] = content
			data['reports'] = this.data.reports
			app.core('post', 'article/report', {...data}, (res) => {
					if (res.resultCode == 200) {
						wx.showToast({
							title: '提交成功',
							icon: 'success',
							duration: 2000
						});

						vm.setData({
							isSubmit: false
						})
						setTimeout(function () {
							wx.navigateBack({
								delta: 1
							})
						}, 1000)
					} else {
						wx.showToast({
							title: '提交失败！',
							icon: 'none',
							duration: 2000
						});
					}
				},
				(err) => {
					console.log(err)
				}
			)

		}

	},
})
